<%@ Page language="vb" CodeFile="searchUw.aspx.vb" Inherits="searchUw_aspx_vb" %>

<%
    rowNumber = 1
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        flushCounter = 0
        sumUw = 0
        If subDo = "print" Then 
            tableWidth = "100%"
            OverPrint()
        Else
            tableWidth = "1000"
            Over()
        End IF
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='" & tableWidth & "'>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td valign='top' colspan='3'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='" & tableWidth & "'>")
        Response.Write("<tr>")
        Response.Write("<td class='headline' colspan='7'>")
        Response.Write("SEARCH UW")
        If Len(subDo) = 0 Then 
            Response.Write("<a href='searchUw.aspx?subDo=print' target='_blank'><img src='gui/printer.gif' align='right' alt='Printable version' border='0'></a>")
        End IF
        Response.Write("<hr class='hrHeadline'>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr bgcolor='#eeeeee'>")
        Response.Write("<td class='formBold'>Country</td>")
        Response.Write("<td class='formBold'>Invoice ID</td>")
        Response.Write("<td class='formBold'>Licence number</td>")
        Response.Write("<td class='formBold'>VIN number</td>")
        Response.Write("<td class='formBold'>UW</td>")
        Response.Write("<td class='formBold'>Invoice date</td>")
        If Len(subDo) = 0 Then 
            Response.Write("<td class='formBold' align='right'></td>")
        End IF
        Response.Write("</tr>")
        rowNumber = 1
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceID, i.invoiceDate, c.country, c.countryCurrency, v.vehicleID, v.regnr, v.vinNumber, pl.uw From ((((tblInvoice i INNER JOIN tblCountry c ON c.countryID = i.countryID) INNER JOIN tblInvoiceContent ic ON ic.invoiceID = i.invoiceID) INNER JOIn tblVehicle v ON v.vehicleID = ic.vehicleID) INNER JOIN tblPriceList pl ON pl.priceListID = ic.priceListID) Where i.invoicePrinted = 1 Order By i.invoiceID, v.regnr")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>No uw results found</font></td></tr>")
        Else
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                uw = RecSet.Fields("uw").Value
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                sumUw = sumUw + uw
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(uw), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & Left(invoiceDate, 10) & "</td>")
                If Len(subDo) = 0 Then 
                    Response.Write("<td align='right'><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                End IF
                Response.Write("</tr>")
                If flushCounter = 100 Then 
                    Response.Flush()
                    flushCounter = 0
                Else
                    flushCounter = flushCounter + 1
                End IF
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select iplm.invoicePriceListModificationID As invoiceID, iplm.invoiceDate, c.country, c.countryCurrency, v.vehicleID, v.regnr, v.vinNumber, pl1.uw As oldUw, pl2.uw As newUw From (((((tblInvoicePriceListModification iplm INNER JOIN tblCountry c ON c.countryID = iplm.countryID) INNER JOIN tblInvoicePriceListModificationContent iplmc ON iplmc.invoicePriceListModificationID = iplm.invoicePriceListModificationID) INNER JOIn tblVehicle v ON v.vehicleID = iplmc.vehicleID) INNER JOIN tblPriceList pl1 ON pl1.priceListID = iplmc.oldPriceListID) INNER JOIN tblPriceList pl2 ON pl2.PriceListID = iplmc.newPriceListID) Where iplm.invoicePrinted = 1 Order By iplm.invoicePriceListModificationID, v.regnr")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>No uw results found</font></td></tr>")
        Else
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                oldUw = RecSet.Fields("oldUw").Value
                newUw = RecSet.Fields("newUw").Value
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                uw = CDbl(newUw) - CDbl(oldUw)
                sumUw = sumUw + uw
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(uw), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & Left(invoiceDate, 10) & "</td>")
                If Len(subDo) = 0 Then 
                    Response.Write("<td align='right'><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                End IF
                Response.Write("</tr>")
                If flushCounter = 100 Then 
                    Response.Flush()
                    flushCounter = 0
                Else
                    flushCounter = flushCounter + 1
                End IF
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceCreditID, i.invoiceDate, c.country, c.countryCurrency, v.vehicleID, v.regnr, v.vinNumber, pl.uw From ((((tblInvoiceCredit i INNER JOIN tblCountry c ON c.countryID = i.countryID) INNER JOIN tblInvoiceCreditContent ic ON ic.invoiceCreditID = i.invoiceCreditID) INNER JOIn tblVehicle v ON v.vehicleID = ic.vehicleID) INNER JOIN tblPriceList pl ON pl.priceListID = ic.priceListID) Where i.invoicePrinted = 1 Order By i.invoiceCreditID, v.regnr")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceCreditID = RecSet.Fields("invoiceCreditID").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                uw = RecSet.Fields("uw").Value
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                sumUw = CDbl(sumUw) - CDbl(uw)
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & invoiceCreditID & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>- " & FormatNumber(CDbl(uw), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & Left(invoiceDate, 10) & "</td>")
                If Len(subDo) = 0 Then 
                    Response.Write("<td align='right'><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                End IF
                Response.Write("</tr>")
                If flushCounter = 100 Then 
                    Response.Flush()
                    flushCounter = 0
                Else
                    flushCounter = flushCounter + 1
                End IF
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceDistancePenaltyID, i.invoiceDate, i.uw, c.country, c.countryCurrency, v.vehicleID, v.regnr, v.vinNumber From ((tblInvoiceDistancePenalty i INNER JOIn tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoicePrinted = 1 Order By i.invoiceDistancePenaltyID, v.regnr")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceDistancePenaltyID = RecSet.Fields("invoiceDistancePenaltyID").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                uw = RecSet.Fields("uw").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                sumUw = sumUw + uw
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & invoiceDistancePenaltyID & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(uw), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & Left(invoiceDate, 10) & "</td>")
                If Len(subDo) = 0 Then 
                    Response.Write("<td align='right'><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                End IF
                Response.Write("</tr>")
                If flushCounter = 100 Then 
                    Response.Flush()
                    flushCounter = 0
                Else
                    flushCounter = flushCounter + 1
                End IF
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceDurationPenaltyID, i.invoiceDate, i.uw, c.country, c.countryCurrency, v.vehicleID, v.regnr, v.vinNumber From ((tblInvoiceDurationPenalty i INNER JOIn tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoicePrinted = 1 Order By i.invoiceDurationPenaltyID, v.regnr")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceDurationPenaltyID = RecSet.Fields("invoiceDurationPenaltyID").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                uw = RecSet.Fields("uw").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                sumUw = sumUw + uw
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & invoiceDurationPenaltyID & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(uw), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & Left(invoiceDate, 10) & "</td>")
                If Len(subDo) = 0 Then 
                    Response.Write("<td align='right'><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                End IF
                Response.Write("</tr>")
                If flushCounter = 100 Then 
                    Response.Flush()
                    flushCounter = 0
                Else
                    flushCounter = flushCounter + 1
                End IF
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        If rowNumber = 0 Then 
            strGrey = " bgcolor='#eeeeee'"
        Else
            strGrey = ""
        End IF
        If CInt(sumUw) > 0 Then 
            Response.Write("<tr" & strGrey & ">")
            Response.Write("<td colspan='4' class='formBold'>Uw sum:</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(sumUw), 2) & " " & countryCurrency & "</td>")
            Response.Write("<td colspan='2'></td>")
            Response.Write("</tr>")
        End IF
        Response.Write("<tr><td colspan='7'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    End IF
%>
